package com.ddx.check;

import com.ddx.common.util.AssertUtil;
import com.ddx.common.util.CheckUtils;
import com.ddx.dto.UserDto;

/**
 * @author dudianbo
 * @ClassName: CheckUserParamValidate
 * @Description: 用户操作校验类
 * @date 2018/4/18
 */
public class CheckUserParamValidate {
    /**
     * 校验登录参数
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkLogin(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getMobile(), "请填写正确的手机号");
        if (!CheckUtils.isPhoneLegal(userDto.getMobile())) {
            throw new IllegalArgumentException("请填写正确的手机号");
        }
        AssertUtil.isNotNull(userDto.getPassword(), "密码为空");
    }

    /**
     * 校验验证码登录参数
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkSmsLogin(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getMobile(), "请填写正确的手机号");
        if (!CheckUtils.isPhoneLegal(userDto.getMobile())) {
            throw new IllegalArgumentException("请填写正确的手机号");
        }
        AssertUtil.isNotNull(userDto.getSmsCode(), "验证码为空");
    }

    /**
     * 校验注册参数
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkRegister(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getMobile(), "请填写正确的手机号");
        if (!CheckUtils.isPhoneLegal(userDto.getMobile())) {
            throw new IllegalArgumentException("请填写正确的手机号");
        }
        AssertUtil.isNotNull(userDto.getSmsCode(), "短信验证码为空");
    }

    /**
     * 校验修改密码接口
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkUpdatePsd(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getPassword(), "修改密码为空");
        AssertUtil.isNotNull(userDto.getOldPsd(), "老密码为空");
    }

    /**
     * 校验修改密码接口（新）
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkNewUpdatePsd(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getPassword(), "修改密码为空");
        AssertUtil.isNotNull(userDto.getSmsCode(), "短信验证码为空");
    }

    /**
     * 修改交易（资金）密码接口
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkTradePsd(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getNewPwd(), "新密码为空");
    }

    /**
     * 修改交易（资金）密码接口（新）
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkNewUpdateTradePsd(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getNewPwd(), "新密码为空");
        AssertUtil.isNotNull(userDto.getSmsCode(), "短信验证码为空");
    }

    /**
     * 校验发送验证码接口
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkSendSms(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getMobile(), "请填写正确的手机号");
        if (!CheckUtils.isPhoneLegal(userDto.getMobile())) {
            throw new IllegalArgumentException("请填写正确的手机号");
        }
        AssertUtil.isNotNull(userDto.getType(), "发送验证码类型为空");
    }

    /**
     * 校验找回密码接口
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkResetPsd(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getPhoneNum(), "请填写正确的手机号");
        if (!CheckUtils.isPhoneLegal(userDto.getPhoneNum())) {
            throw new IllegalArgumentException("请填写正确的手机号");
        }
        AssertUtil.isNotNull(userDto.getSmsCode(), "验证码为空");
        AssertUtil.isNotNull(userDto.getPassword(), "密码为空");
        AssertUtil.isNotNull(userDto.getType(), "类型为空");
    }

    /**
     * 校验找回密码接口
     *
     * @param userDto
     * @throws IllegalArgumentException
     */
    public static void checkRealNameAuth(UserDto userDto) throws IllegalArgumentException {
        AssertUtil.isNotNull(userDto.getPhoneNum(), "请填写正确的手机号");
        if (!CheckUtils.isPhoneLegal(userDto.getPhoneNum())) {
            throw new IllegalArgumentException("请填写正确的手机号");
        }
        AssertUtil.isNotNull(userDto.getSmsCode(), "验证码为空");
        AssertUtil.isNotNull(userDto.getIdCard(), "身份证号为空");
        AssertUtil.isNotNull(userDto.getRealName(), "真实姓名为空");
    }
}
